import { AudioManager } from './AudioManager';
import { AudioManager_manbo } from './AudioManager_manbo';
import { _decorator, Component, Input, AudioClip, AudioSource, resources, instantiate, Node, Prefab, tween, Vec3, 
Vec2, input, Tween, Animation, Director, Label} from 'cc';
const { ccclass, property } = _decorator;
@ccclass('Game')
export class Game extends Component {
    // 音效节点
    @property ({type:AudioManager})
    private audioManager:AudioManager = null;
    @property ({type:AudioManager_manbo})
    private audioManager_manbo:AudioManager_manbo = null;
    @property({ type: Prefab })
    private preBulletNode: Prefab = null;
    // 敌人预制体
    @property({ type: Prefab })
    private preEnemyNode: Prefab = null;
    // 攻击手预制体
    @property({ type: Prefab })
    private prePlantNode: Prefab = null;
    // 绑定敌人节点
    @property({ type: Node })
    private enemysNode: Node = null;
    // 绑定火堆组节点
    @property({ type: Node })
    private bonFireArr: Node = null;
    // 绑定攻击手节点
    @property({ type: Node })
    private plantsNode: Node = null;
    @property({ type: Node })
    private plantNode: Node = null;
    // 子弹挂载到道路节点，方便监测是否攻击到敌人
    @property({ type: Node })
    private road1: Node = null;
    @property({ type: Node })
    private road2: Node = null;
    @property({ type: Node })
    private road3: Node = null;
    @property({ type: Node })
    private road4: Node = null;
    @property({ type: Node })
    private road5: Node = null;
    // 绑定所有Buff选项
    @property({ type: Node })
    private buff1: Node = null;
    @property({ type: Node })
    private buff2: Node = null;
    @property({ type: Node })
    private buff3: Node = null;
    @property({ type: Node })
    private buff4: Node = null;
    @property({ type: Node })
    private buff5: Node = null;
    // 绑定buff提示面板
    @property({ type: Node })
    private Tip: Node = null;
    // 绑定获得buff数量文本
    @property({ type: Label })
    private buffsumsLabel: Label = null;
    // 绑定禁止种植攻击手功能背景
    @property({ type: Node })
    private noneNum: Node = null;
    // 绑定禁止放置火堆功能背景
    @property({ type: Node })
    private noneFire: Node = null;
    // 绑定游戏结束界面
    @property({ type: Node })
    private GameOver: Node = null;
    // 绑定火堆预制体
    @property({ type: Prefab })
    private bonFirePrefab: Prefab = null;
    // 绑定火堆节点
    @property({ type: Node })
    private bonFireNode: Node = null;
    // 绑定得分节点
    @property({ type: Label })
    private getScore: Label = null;
    // 绑定最终得分节点
    @property({ type: Label })
    private endScore: Label = null;

    // 敌人行走的道路，方便后续实现攻击手攻击功能
    private enemyArr1 = [];
    private enemyArr2 = [];
    private enemyArr3 = [];
    private enemyArr4 = [];
    private enemyArr5 = [];
    // 攻击手种植道路
    private plantArr1 = [null,null,null,null,null,null,null,null];
    private plantArr2 = [null,null,null,null,null,null,null,null];
    private plantArr3 = [null,null,null,null,null,null,null,null];
    private plantArr4 = [null,null,null,null,null,null,null,null];
    private plantArr5 = [null,null,null,null,null,null,null,null];
    // 每条道路已种植攻击手数量
    private plantLength1 = 0;
    private plantLength2 = 0;
    private plantLength3 = 0;
    private plantLength4 = 0;
    private plantLength5 = 0;
    // 火堆放置的道路号，方便后续实现敌人行走在火堆上扣血功能
    private bonFireArr1 = [];
    private bonFireArr2 = [];
    private bonFireArr3 = [];
    private bonFireArr4 = [];
    private bonFireArr5 = [];
    // 关卡增加，敌人难度增加
    // 敌人行走速度
    private enemySpeed = 20;
    // 敌人生成速度
    private createSpeed = 2000;
    // 敌人血量
    private enemyHp = 10;
    // 设置定时器
    private timer = null;
    // 设置攻击手攻速
    private plantSpeed = 1000;
    // 设置攻击手攻击力
    private plantATK = 4;
    // 攻击手攻击贯穿数
    private crossNums = 0;
    // 可种植攻击手数量
    private plantNums = 5;
    // 已种植攻击手数量
    private isPlantNums = 0;
    // 可放置火堆数量
    private bonfireNums = 0;
    // 已放置火堆数量
    private isbonfireNums = 0;
    // 火堆伤害
    private bonFireATk = 1;
    // 玩家可选择的Buff库;
    private Buffs = [];
    // 控制buff选择界面是否产生,0为未产生buff，1为已产生
    private isBuff = 0;
    // 玩家持有buff数，每增加获得5个buff，怪物掉落buff概率减少0.01，但玩家最多选择50次buff，每个buff被玩家选择5次后会升级
    private getBuffNums = 0
    // 怪物掉落buff概率，初始为0.1
    private getBuffChance = 0.1
    // 怪物每次增强时增加的血量
    private addHp = 5
    // 为不同列的攻击手设置不同的缓动动作执行时长，来控制子弹在不同列的速度相同
    // 最左侧格子为第一格
    private Column1 = 3
    private Column2 = 3900 / 1420
    private Column3 = 3540 / 1420
    private Column4 = 3180 / 1420
    private Column5 = 2820 / 1420
    private Column6 = 2460 / 1420
    private Column7 = 2100 / 1420
    private Column8 = 1740 / 1420
    // 每个格子可种植的攻击手数量，重复种植可以增强攻击手属性
    // 5行8列
    private plantList = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
    // 玩家得分
    private score = 0;
    // 音效节点
    private audioSource:AudioSource | null = null

    onLoad() {
        // 添加AudioSource组件
        this.audioSource = this.node.addComponent(AudioSource)

        this.Buffs.push(this.buff1)
        this.Buffs.push(this.buff2)
        this.Buffs.push(this.buff3)
        this.Buffs.push(this.buff4)
        // 鼠标（MOUSE_DOWN）、或手指点击屏幕生成攻击手节点
        this.plantNode.on(Input.EventType.TOUCH_START, () => {
            this.createPlant()
        }, this)
        // 再次点击屏幕确认种植攻击手
        input.on(Input.EventType.TOUCH_END, (e) => {    
            for (var i = 0; i < this.plantsNode.children.length; i++) {
                let x = this.plantsNode.children[i]['x']-1;
                let y = this.plantsNode.children[i]['y']-1;
                let plantSize = 0;
                if (this.plantsNode.children[i]['isdown'] == 0 && this.plantsNode.children[i]['isgrid'] == 1) {
                    if (y==0) {
                        console.log(x)
                        // 每个格子最多种植3棵攻击手
                        if(this.plantList[y][x] >= 3){break}
                        this.plantList[y][x] += 1
                        // 设置多次种植后的攻击手大小，方便玩家知道种植了多少次
                        plantSize = 1 + 0.25*(this.plantList[y][x]-1)
                        this.plantsNode.children[i].setScale(plantSize,plantSize,plantSize)
                        // 根据攻击手y坐标派分分路,若该格子已经种植过攻击手则不添加
                        // 删除尾元素并停止攻击行为，方便后续写敌人吃掉攻击手函数
                        if(this.plantList[y][x]>1){
                            let plantNode = this.plantArr1[x]
                            plantNode.destroy()
                            plantNode['isFire'] = 0;
                            plantNode.active = false
                            this.plantArr1[x] = null
                            plantNode.destroy()
                        }
                        // 设置攻击手数组的值
                        this.plantArr1[x]=this.plantsNode.children[i];
                        // 对应分路已种植数量+1
                        this.plantLength1 += 1;
                    } else if (y==1) {
                         // 每个格子最多种植3棵攻击手
                         if(this.plantList[y][x] >= 3){break}
                         this.plantList[y][x] += 1
                         // 设置多次种植后的攻击手大小，方便玩家知道种植了多少次
                         plantSize = 1 + 0.25*(this.plantList[y][x]-1)
                         this.plantsNode.children[i].setScale(plantSize,plantSize,plantSize)
                         // 根据攻击手y坐标派分分路,若该格子已经种植过攻击手则不添加
                         // 删除尾元素并停止攻击行为，方便后续写敌人吃掉攻击手函数
                         if(this.plantList[y][x]>1){
                             let plantNode = this.plantArr2[x]
                             plantNode.destroy()
                             plantNode['isFire'] = 0;
                             plantNode.active = false
                             this.plantArr2[x] = null
                             plantNode.destroy()
                         }
                         // 设置攻击手数组的值
                         this.plantArr2[x]=this.plantsNode.children[i];
                         // 对应分路已种植数量+1
                         this.plantLength2 += 1;
                    } else if (y==2) {
                         // 每个格子最多种植3棵攻击手
                         if(this.plantList[y][x] >= 3){break}
                         this.plantList[y][x] += 1
                         // 设置多次种植后的攻击手大小，方便玩家知道种植了多少次
                         plantSize = 1 + 0.25*(this.plantList[y][x]-1)
                         this.plantsNode.children[i].setScale(plantSize,plantSize,plantSize)
                         // 根据攻击手y坐标派分分路,若该格子已经种植过攻击手则不添加
                         // 删除尾元素并停止攻击行为，方便后续写敌人吃掉攻击手函数
                         if(this.plantList[y][x]>1){
                             let plantNode = this.plantArr3[x]
                             plantNode.destroy()
                             plantNode['isFire'] = 0;
                             plantNode.active = false
                             this.plantArr3[x] = null
                             plantNode.destroy()
                         }
                         // 设置攻击手数组的值
                         this.plantArr3[x]=this.plantsNode.children[i];
                         // 对应分路已种植数量+1
                         this.plantLength3 += 1;
                    } else if (y==3) {
                         // 每个格子最多种植3棵攻击手
                         if(this.plantList[y][x] >= 3){break}
                         this.plantList[y][x] += 1
                         // 设置多次种植后的攻击手大小，方便玩家知道种植了多少次
                         plantSize = 1 + 0.25*(this.plantList[y][x]-1)
                         this.plantsNode.children[i].setScale(plantSize,plantSize,plantSize)
                         // 根据攻击手y坐标派分分路,若该格子已经种植过攻击手则不添加
                         // 删除尾元素并停止攻击行为，方便后续写敌人吃掉攻击手函数
                         if(this.plantList[y][x]>1){
                             let plantNode = this.plantArr4[x]
                             plantNode.destroy()
                             plantNode['isFire'] = 0;
                             plantNode.active = false
                             this.plantArr4[x] = null
                             plantNode.destroy()
                         }
                         // 设置攻击手数组的值
                         this.plantArr4[x]=this.plantsNode.children[i];
                         // 对应分路已种植数量+1
                         this.plantLength4 += 1;
                    } else {
                         // 每个格子最多种植3棵攻击手
                         if(this.plantList[y][x] >= 3){break}
                         this.plantList[y][x] += 1
                         // 设置多次种植后的攻击手大小，方便玩家知道种植了多少次
                         plantSize = 1 + 0.25*(this.plantList[y][x]-1)
                         this.plantsNode.children[i].setScale(plantSize,plantSize,plantSize)
                         // 根据攻击手y坐标派分分路,若该格子已经种植过攻击手则不添加
                         // 删除尾元素并停止攻击行为，方便后续写敌人吃掉攻击手函数
                         if(this.plantList[y][x]>1){
                             let plantNode = this.plantArr5[x]
                             plantNode.destroy()
                             plantNode['isFire'] = 0;
                             plantNode.active = false
                             this.plantArr5[x] = null
                             
                         }
                         // 设置攻击手数组的值
                         this.plantArr5[x]=this.plantsNode.children[i];
                         // 对应分路已种植数量+1
                         this.plantLength5 += 1;
                    }
                    this.plantsNode.children[i]['isdown'] = 1;
                    // 每种植一棵攻击手，已种植攻击手数量+1
                    this.isPlantNums += 1;
                    // 种下攻击手在对于分路的序号
                    this.plantsNode.children[i]['num'] = x
                    clearInterval(this.timer)
                } else {
                    continue
                }
            }
        }, this)
        // 移动攻击手节点
        this.plantNode.on(Input.EventType.TOUCH_MOVE, (e) => {
            // console.log("move")
            for (var i = 0; i < this.plantsNode.children.length; i++) {
                // if(this.plantsNode.children[i]['isgrid']==1)return;
                if (this.plantsNode.children[i]['isdown'] == 0) {
                    this.plantsNode.children[i].setWorldPosition(new Vec3(e.getUILocation().x + 480, e.getUILocation().y, 0))
                    this.plantsNode.children[i]['isgrid'] = 0;

                    // 方便种植攻击手，当攻击手靠近某格时自动设置位置到该格子中间
                    // 第一行
                    const gridY1 = 250;
                    // 第二行
                    const gridY2 = 130;
                    // 第三行
                    const gridY3 = 10;
                    // 第四行
                    const gridY4 = -110;
                    // 第五行
                    const gridY5 = -230;
                    // 第1-8格
                    const gridX1 = -420;
                    const gridX2 = -300;
                    const gridX3 = -180;
                    const gridX4 = -60;
                    const gridX5 = 60;
                    const gridX6 = 180;
                    const gridX7 = 300;
                    const gridX8 = 420;
                    // 设置表格行数
                    let Y1 = 1
                    let Y2 = 2
                    let Y3 = 3
                    let Y4 = 4
                    let Y5 = 5
                    // 设置表格列数
                    let X1 = 1
                    let X2 = 2
                    let X3 = 3
                    let X4 = 4
                    let X5 = 5
                    let X6 = 6
                    let X7 = 7
                    let X8 = 8
                    // 攻击手行数
                    let plantGridy;
                    // 攻击手格数
                    let plantGridx;
                    // 攻击手表格行列数
                    let PlantY = 0
                    let PlantX = 0
                    // 判断行数
                    // 1
                    if(this.plantsNode.children[i].position.y < 310 &&this.plantsNode.children[i].position.y > 190){
                        plantGridy = gridY1
                        PlantY = Y1
                    }
                    // 2
                    if(this.plantsNode.children[i].position.y < 180 &&this.plantsNode.children[i].position.y > 60){
                        plantGridy = gridY2
                        PlantY = Y2
                    }
                    // 3
                    if(this.plantsNode.children[i].position.y < 60 &&this.plantsNode.children[i].position.y > -60){
                        plantGridy = gridY3
                        PlantY = Y3
                    }
                    // 4
                    if(this.plantsNode.children[i].position.y < -60 &&this.plantsNode.children[i].position.y > -180){
                        plantGridy = gridY4
                        PlantY = Y4
                    }
                    // 5
                    if(this.plantsNode.children[i].position.y < -180 &&this.plantsNode.children[i].position.y > -300){
                        plantGridy = gridY5
                        PlantY = Y5
                    }
                    // 判断格数
                    // 1
                    if(this.plantsNode.children[i].position.x < -360 &&this.plantsNode.children[i].position.x > -480){
                        plantGridx = gridX1
                        PlantX = X1
                    }
                    // 2
                    if(this.plantsNode.children[i].position.x < -240 &&this.plantsNode.children[i].position.x > -360){
                        plantGridx = gridX2
                        PlantX = X2
                    }
                    // 3
                    if(this.plantsNode.children[i].position.x < -120 &&this.plantsNode.children[i].position.x > -240){
                        plantGridx = gridX3
                        PlantX = X3
                    }
                    // 4
                    if(this.plantsNode.children[i].position.x < 0 &&this.plantsNode.children[i].position.x > -120){
                        plantGridx = gridX4
                        PlantX = X4
                    }
                    // 5
                    if(this.plantsNode.children[i].position.x < 120 &&this.plantsNode.children[i].position.x > 0){
                        plantGridx = gridX5
                        PlantX = X5
                    }
                    // 6
                    if(this.plantsNode.children[i].position.x < 240 &&this.plantsNode.children[i].position.x > 120){
                        plantGridx = gridX6
                        PlantX = X6
                    }
                    // 7
                    if(this.plantsNode.children[i].position.x < 360 &&this.plantsNode.children[i].position.x > 240){
                        plantGridx = gridX7
                        PlantX = X7
                    }
                    // 8
                    if(this.plantsNode.children[i].position.x < 480 &&this.plantsNode.children[i].position.x > 360){
                        plantGridx = gridX8
                        PlantX = X8
                    }
                    this.plantsNode.children[i].setPosition(new Vec3(plantGridx, plantGridy, 0))
                    // 若两秒后未确认种植攻击手，攻击手自动回归；(再次点击屏幕确认种植)
                    this.plantsNode.children[i]['isgrid'] = 1;
                    this.plantsNode.children[i]['x'] = PlantX;
                    this.plantsNode.children[i]['y'] = PlantY;


                    
                    // 如果该攻击手未“确认”种植，在两秒后将自动归位
                    if (this.plantsNode.children[i]['isdown'] == 0) {
                        clearInterval(this.timer)
                        let a = i
                        this.timer = setInterval(() => {
                            this.plantsNode.children[a].setPosition(new Vec3(-550, 240, 0))
                            clearInterval(this.timer)
                        }, 2000)
                    }
                }
            }
        }, this)

        // 火堆的生成与放置
        this.bonFireNode.on(Input.EventType.TOUCH_START, () => {
            console.log("Fire")
            this.createBonfire()
        }, this)
        this.bonFireNode.on(Input.EventType.TOUCH_MOVE,(e)=>{
            for (var i = 0; i < this.bonFireArr.children.length; i++) {
                if (this.bonFireArr.children[i]['isdown'] == 0) {
                    this.bonFireArr.children[i].setWorldPosition(new Vec3(e.getUILocation().x, e.getUILocation().y, 0))
                    this.bonFireArr.children[i]['isgrid'] = 0;
                    // 方便种植攻击手，当攻击手靠近某格时自动设置位置到该格子中间
                    switch (true) {
                        // 1-1
                        case this.bonFireArr.children[i].position.y < 310 &&
                            this.bonFireArr.children[i].position.y > 190 &&
                            this.bonFireArr.children[i].position.x < -360 &&
                            this.bonFireArr.children[i].position.x > -480:
                            this.bonFireArr.children[i].setPosition(new Vec3(-420, 250, 0))
                            // 若两秒后未确认种植攻击手，攻击手自动回归；(再次点击屏幕确认种植)
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 1-2
                        case this.bonFireArr.children[i].position.y < 310 &&
                            this.bonFireArr.children[i].position.y > 190 &&
                            this.bonFireArr.children[i].position.x < -240 &&
                            this.bonFireArr.children[i].position.x > -360:
                            this.bonFireArr.children[i].setPosition(new Vec3(-300, 250, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 1-3
                        case this.bonFireArr.children[i].position.y < 310 &&
                            this.bonFireArr.children[i].position.y > 190 &&
                            this.bonFireArr.children[i].position.x < -120 &&
                            this.bonFireArr.children[i].position.x > -240:
                            this.bonFireArr.children[i].setPosition(new Vec3(-180, 250, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 1-4
                        case this.bonFireArr.children[i].position.y < 310 &&
                            this.bonFireArr.children[i].position.y > 190 &&
                            this.bonFireArr.children[i].position.x < 0 &&
                            this.bonFireArr.children[i].position.x > -120:
                            this.bonFireArr.children[i].setPosition(new Vec3(-60, 250, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 1-5
                        case this.bonFireArr.children[i].position.y < 310 &&
                            this.bonFireArr.children[i].position.y > 190 &&
                            this.bonFireArr.children[i].position.x < 120 &&
                            this.bonFireArr.children[i].position.x > 0:
                            this.bonFireArr.children[i].setPosition(new Vec3(60, 250, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 1-6
                        case this.bonFireArr.children[i].position.y < 310 &&
                            this.bonFireArr.children[i].position.y > 190 &&
                            this.bonFireArr.children[i].position.x < 240 &&
                            this.bonFireArr.children[i].position.x > 120:
                            this.bonFireArr.children[i].setPosition(new Vec3(180, 250, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 1-7
                        case this.bonFireArr.children[i].position.y < 310 &&
                            this.bonFireArr.children[i].position.y > 190 &&
                            this.bonFireArr.children[i].position.x < 360 &&
                            this.bonFireArr.children[i].position.x > 240:
                            this.bonFireArr.children[i].setPosition(new Vec3(300, 250, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 1-8
                        case this.bonFireArr.children[i].position.y < 310 &&
                            this.bonFireArr.children[i].position.y > 190 &&
                            this.bonFireArr.children[i].position.x < 480 &&
                            this.bonFireArr.children[i].position.x > 360:
                            this.bonFireArr.children[i].setPosition(new Vec3(420, 250, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 第二行
                        // 2-1
                        case this.bonFireArr.children[i].position.y < 180 &&
                            this.bonFireArr.children[i].position.y > 60 &&
                            this.bonFireArr.children[i].position.x < -360 &&
                            this.bonFireArr.children[i].position.x > -480:
                            this.bonFireArr.children[i].setPosition(new Vec3(-420, 130, 0))
                            // 若两秒后未确认种植攻击手，攻击手自动回归；(再次点击屏幕确认种植)
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 2-2
                        case this.bonFireArr.children[i].position.y < 180 &&
                            this.bonFireArr.children[i].position.y > 60 &&
                            this.bonFireArr.children[i].position.x < -240 &&
                            this.bonFireArr.children[i].position.x > -360:
                            this.bonFireArr.children[i].setPosition(new Vec3(-300, 130, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 2-3
                        case this.bonFireArr.children[i].position.y < 180 &&
                            this.bonFireArr.children[i].position.y > 60 &&
                            this.bonFireArr.children[i].position.x < -120 &&
                            this.bonFireArr.children[i].position.x > -240:
                            this.bonFireArr.children[i].setPosition(new Vec3(-180, 130, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 2-4
                        case this.bonFireArr.children[i].position.y < 180 &&
                            this.bonFireArr.children[i].position.y > 60 &&
                            this.bonFireArr.children[i].position.x < 0 &&
                            this.bonFireArr.children[i].position.x > -120:
                            this.bonFireArr.children[i].setPosition(new Vec3(-60, 130, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 2-5
                        case this.bonFireArr.children[i].position.y < 180 &&
                            this.bonFireArr.children[i].position.y > 60 &&
                            this.bonFireArr.children[i].position.x < 120 &&
                            this.bonFireArr.children[i].position.x > 0:
                            this.bonFireArr.children[i].setPosition(new Vec3(60, 130, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 2-6
                        case this.bonFireArr.children[i].position.y < 180 &&
                            this.bonFireArr.children[i].position.y > 60 &&
                            this.bonFireArr.children[i].position.x < 240 &&
                            this.bonFireArr.children[i].position.x > 120:
                            this.bonFireArr.children[i].setPosition(new Vec3(180, 130, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 2-7
                        case this.bonFireArr.children[i].position.y < 180 &&
                            this.bonFireArr.children[i].position.y > 60 &&
                            this.bonFireArr.children[i].position.x < 360 &&
                            this.bonFireArr.children[i].position.x > 240:
                            this.bonFireArr.children[i].setPosition(new Vec3(300, 130, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 2-8
                        case this.bonFireArr.children[i].position.y < 180 &&
                            this.bonFireArr.children[i].position.y > 60 &&
                            this.bonFireArr.children[i].position.x < 480 &&
                            this.bonFireArr.children[i].position.x > 360:
                            this.bonFireArr.children[i].setPosition(new Vec3(420, 130, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 第三行
                        // 3-1
                        case this.bonFireArr.children[i].position.y < 60 &&
                            this.bonFireArr.children[i].position.y > -60 &&
                            this.bonFireArr.children[i].position.x < -360 &&
                            this.bonFireArr.children[i].position.x > -480:
                            this.bonFireArr.children[i].setPosition(new Vec3(-420, 10, 0))
                            // 若两秒后未确认种植攻击手，攻击手自动回归；(再次点击屏幕确认种植)
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 3-2
                        case this.bonFireArr.children[i].position.y < 60 &&
                            this.bonFireArr.children[i].position.y > -60 &&
                            this.bonFireArr.children[i].position.x < -240 &&
                            this.bonFireArr.children[i].position.x > -360:
                            this.bonFireArr.children[i].setPosition(new Vec3(-300, 10, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 3-3
                        case this.bonFireArr.children[i].position.y < 60 &&
                            this.bonFireArr.children[i].position.y > -60 &&
                            this.bonFireArr.children[i].position.x < -120 &&
                            this.bonFireArr.children[i].position.x > -240:
                            this.bonFireArr.children[i].setPosition(new Vec3(-180, 10, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 3-4
                        case this.bonFireArr.children[i].position.y < 60 &&
                            this.bonFireArr.children[i].position.y > -60 &&
                            this.bonFireArr.children[i].position.x < 0 &&
                            this.bonFireArr.children[i].position.x > -120:
                            this.bonFireArr.children[i].setPosition(new Vec3(-60, 10, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 3-5
                        case this.bonFireArr.children[i].position.y < 60 &&
                            this.bonFireArr.children[i].position.y > -60 &&
                            this.bonFireArr.children[i].position.x < 120 &&
                            this.bonFireArr.children[i].position.x > 0:
                            this.bonFireArr.children[i].setPosition(new Vec3(60, 10, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 3-6
                        case this.bonFireArr.children[i].position.y < 60 &&
                            this.bonFireArr.children[i].position.y > -60 &&
                            this.bonFireArr.children[i].position.x < 240 &&
                            this.bonFireArr.children[i].position.x > 120:
                            this.bonFireArr.children[i].setPosition(new Vec3(180, 10, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 3-7
                        case this.bonFireArr.children[i].position.y < 60 &&
                            this.bonFireArr.children[i].position.y > -60 &&
                            this.bonFireArr.children[i].position.x < 360 &&
                            this.bonFireArr.children[i].position.x > 240:
                            this.bonFireArr.children[i].setPosition(new Vec3(300, 10, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 3-8
                        case this.bonFireArr.children[i].position.y < 60 &&
                            this.bonFireArr.children[i].position.y > -60 &&
                            this.bonFireArr.children[i].position.x < 480 &&
                            this.bonFireArr.children[i].position.x > 360:
                            this.bonFireArr.children[i].setPosition(new Vec3(420, 10, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 第四行
                        // 4-1
                        case this.bonFireArr.children[i].position.y < -60 &&
                            this.bonFireArr.children[i].position.y > -180 &&
                            this.bonFireArr.children[i].position.x < -360 &&
                            this.bonFireArr.children[i].position.x > -480:
                            this.bonFireArr.children[i].setPosition(new Vec3(-420, -110, 0))
                            // 若两秒后未确认种植攻击手，攻击手自动回归；(再次点击屏幕确认种植)
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 4-2
                        case this.bonFireArr.children[i].position.y < -60 &&
                            this.bonFireArr.children[i].position.y > -180 &&
                            this.bonFireArr.children[i].position.x < -240 &&
                            this.bonFireArr.children[i].position.x > -360:
                            this.bonFireArr.children[i].setPosition(new Vec3(-300, -110, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 4-3
                        case this.bonFireArr.children[i].position.y < -60 &&
                            this.bonFireArr.children[i].position.y > -180 &&
                            this.bonFireArr.children[i].position.x < -120 &&
                            this.bonFireArr.children[i].position.x > -240:
                            this.bonFireArr.children[i].setPosition(new Vec3(-180, -110, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 4-4
                        case this.bonFireArr.children[i].position.y < -60 &&
                            this.bonFireArr.children[i].position.y > -180 &&
                            this.bonFireArr.children[i].position.x < 0 &&
                            this.bonFireArr.children[i].position.x > -120:
                            this.bonFireArr.children[i].setPosition(new Vec3(-60, -110, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 4-5
                        case this.bonFireArr.children[i].position.y < -60 &&
                            this.bonFireArr.children[i].position.y > -180 &&
                            this.bonFireArr.children[i].position.x < 120 &&
                            this.bonFireArr.children[i].position.x > 0:
                            this.bonFireArr.children[i].setPosition(new Vec3(60, -110, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 4-6
                        case this.bonFireArr.children[i].position.y < -60 &&
                            this.bonFireArr.children[i].position.y > -180 &&
                            this.bonFireArr.children[i].position.x < 240 &&
                            this.bonFireArr.children[i].position.x > 120:
                            this.bonFireArr.children[i].setPosition(new Vec3(180, -110, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 4-7
                        case this.bonFireArr.children[i].position.y < -60 &&
                            this.bonFireArr.children[i].position.y > -180 &&
                            this.bonFireArr.children[i].position.x < 360 &&
                            this.bonFireArr.children[i].position.x > 240:
                            this.bonFireArr.children[i].setPosition(new Vec3(300, -110, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 4-8
                        case this.bonFireArr.children[i].position.y < -60 &&
                            this.bonFireArr.children[i].position.y > -180 &&
                            this.bonFireArr.children[i].position.x < 480 &&
                            this.bonFireArr.children[i].position.x > 360:
                            this.bonFireArr.children[i].setPosition(new Vec3(420, -110, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 第五行
                        // 5-1
                        case this.bonFireArr.children[i].position.y < -180 &&
                            this.bonFireArr.children[i].position.y > -300 &&
                            this.bonFireArr.children[i].position.x < -360 &&
                            this.bonFireArr.children[i].position.x > -480:
                            this.bonFireArr.children[i].setPosition(new Vec3(-420, -230, 0))
                            // 若两秒后未确认种植攻击手，攻击手自动回归；(再次点击屏幕确认种植)
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 5-2
                        case this.bonFireArr.children[i].position.y < -180 &&
                            this.bonFireArr.children[i].position.y > -300 &&
                            this.bonFireArr.children[i].position.x < -240 &&
                            this.bonFireArr.children[i].position.x > -360:
                            this.bonFireArr.children[i].setPosition(new Vec3(-300, -230, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 5-3
                        case this.bonFireArr.children[i].position.y < -180 &&
                            this.bonFireArr.children[i].position.y > -300 &&
                            this.bonFireArr.children[i].position.x < -120 &&
                            this.bonFireArr.children[i].position.x > -240:
                            this.bonFireArr.children[i].setPosition(new Vec3(-180, -230, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 5-4
                        case this.bonFireArr.children[i].position.y < -180 &&
                            this.bonFireArr.children[i].position.y > -300 &&
                            this.bonFireArr.children[i].position.x < 0 &&
                            this.bonFireArr.children[i].position.x > -120:
                            this.bonFireArr.children[i].setPosition(new Vec3(-60, -230, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 5-5
                        case this.bonFireArr.children[i].position.y < -180 &&
                            this.bonFireArr.children[i].position.y > -300 &&
                            this.bonFireArr.children[i].position.x < 120 &&
                            this.bonFireArr.children[i].position.x > 0:
                            this.bonFireArr.children[i].setPosition(new Vec3(60, -230, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 5-6
                        case this.bonFireArr.children[i].position.y < -180 &&
                            this.bonFireArr.children[i].position.y > -300 &&
                            this.bonFireArr.children[i].position.x < 240 &&
                            this.bonFireArr.children[i].position.x > 120:
                            this.bonFireArr.children[i].setPosition(new Vec3(180, -230, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 5-7
                        case this.bonFireArr.children[i].position.y < -180 &&
                            this.bonFireArr.children[i].position.y > -300 &&
                            this.bonFireArr.children[i].position.x < 360 &&
                            this.bonFireArr.children[i].position.x > 240:
                            this.bonFireArr.children[i].setPosition(new Vec3(300, -230, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                        // 5-8
                        case this.bonFireArr.children[i].position.y < -180 &&
                            this.bonFireArr.children[i].position.y > -300 &&
                            this.bonFireArr.children[i].position.x < 480 &&
                            this.bonFireArr.children[i].position.x > 360:
                            this.bonFireArr.children[i].setPosition(new Vec3(420, -230, 0))
                            this.bonFireArr.children[i]['isgrid'] = 1;
                            break;
                    }
                    // 如果该攻击手未“确认”种植，在两秒后将自动归位
                    if (this.bonFireArr.children[i]['isdown'] == 0) {
                        clearInterval(this.timer)
                        let a = i
                        this.timer = setInterval(() => {
                            this.bonFireArr.children[a].setPosition(new Vec3(-550, 70, 0))
                            clearInterval(this.timer)
                        }, 2000)
                    }
                }
            }
        },this)
        input.on(Input.EventType.TOUCH_END,(e)=>{
            console.log("Fireend")
            for (var i = 0; i < this.bonFireArr.children.length; i++) {
                let x = 0;
                let y = 0;
                if (this.bonFireArr.children[i].position.x == -420) {
                    x = 0
                } else if (this.bonFireArr.children[i].position.x == -300) {
                    x = 1
                } else if (this.bonFireArr.children[i].position.x == -180) {
                    x = 2
                } else if (this.bonFireArr.children[i].position.x == -60) {
                    x = 3
                } else if (this.bonFireArr.children[i].position.x == 60) {
                    x = 4
                } else if (this.bonFireArr.children[i].position.x == 180) {
                    x = 5
                } else if (this.bonFireArr.children[i].position.x == 300) {
                    x = 6
                } else if (this.bonFireArr.children[i].position.x == 420) {
                    x = 7
                }
                if (this.bonFireArr.children[i]['isdown'] == 0 && this.bonFireArr.children[i]['isgrid'] == 1) {
                    if (this.bonFireArr.children[i].position.y == 250) {
                        y = 0
                        // 每个格子只能种植攻击手或放置火堆
                        if(this.plantList[y][x] >= 1){break}
                        // 直接将放置火堆格子种植数设为3，后续无法种植攻击手与放置火堆
                        this.plantList[y][x] += 3
                        // 根据攻击手y坐标派分分路
                        this.bonFireArr1.push(this.bonFireArr.children[i]);
                    } else if (this.bonFireArr.children[i].position.y == 130) {
                        y = 1
                        if(this.plantList[y][x] >= 1){break}
                        this.plantList[y][x] += 3
                        this.bonFireArr2.push(this.bonFireArr.children[i]);
                        this.bonFireArr.children[i]['num'] = this.plantArr2.length - 1;
                    } else if (this.bonFireArr.children[i].position.y == 10) {
                        y = 2
                        if(this.plantList[y][x] >= 1){break}
                        this.plantList[y][x] += 3
                        this.bonFireArr3.push(this.bonFireArr.children[i]);
                    } else if (this.bonFireArr.children[i].position.y == -110) {
                        y = 3
                        if(this.plantList[y][x] >= 1){break}
                        this.plantList[y][x] += 3
                        this.bonFireArr4.push(this.bonFireArr.children[i]);
                    } else {
                        y = 4
                        if(this.plantList[y][x] >= 1){break}
                        this.plantList[y][x] += 3
                        this.bonFireArr5.push(this.bonFireArr.children[i]);
                    }
                    this.bonFireArr.children[i]['isdown'] = 1;
                    // 每放置一个火堆，放置火堆数+1
                    this.isbonfireNums += 1;
                    clearInterval(this.timer)
                } else {
                    continue
                }
            }
        },this)
    }
    start() {
        this.noneFire.active = false

        // 初始状态下buff选择界面不显示
        this.Tip.active = false;
        // 初始状态下游戏结束界面不显示
        this.GameOver.active = false
        // 初始状态下禁止种植攻击手背景不显示
        this.noneNum.active = false;
        // 一直产生敌人
        this.createEnemyTimer()
        this.getbuff();
        // 设置定时器检查敌人能否吃掉攻击手与检测每条路是否有敌人
        let checkEat = null
        checkEat = setInterval(() => {
            // 敌人吃掉攻击手
            this.checkeat1();
            this.checkeat2();
            this.checkeat3();
            this.checkeat4();
            this.checkeat5();
            // 动态监测每条路是否有敌人
            this.checkenemy1();
            this.checkenemy2();
            this.checkenemy3();
            this.checkenemy4();
            this.checkenemy5();
        }, 200)
    }
    // 游戏结束
    gameOver() {
        this.GameOver.active = true;
    }
    // 监测道路是否有敌人，自动开始攻击
    // 监测道具与攻击手是否达到放置上限
    update() {
        // 当火堆数达上限，遮盖背景显示
        if (this.isbonfireNums == this.bonfireNums) {
            this.noneFire.active = true
        } else {
            this.noneFire.active = false
        }
        // 当种植攻击手达上限时，遮盖背景显示
        if (this.isPlantNums == this.plantNums) {
            this.noneNum.active = true
        } else {
            this.noneNum.active = false
        }
        // 每条分路有敌人攻击手自动发起攻击
        if (this.enemyArr1.length != 0) {
            // console.log(this.enemyArr2.length)
            for (var i = 0; i < this.bonFireArr1.length; i++) {
                this.bonFireAttack1(this.bonFireArr1[i])
            }
            if (this.plantArr1.length == 0) return
            for (var i = 0; i < 8; i++) {
                // 若节点为空则开始下一轮循环
                if(this.road1.children[i]==null)continue
                this.checkAttack1(this.road1.children[i])
            }
        }
        if (this.enemyArr2.length != 0) {
            // console.log(this.enemyArr2.length)
            for (var i = 0; i < this.bonFireArr2.length; i++) {
                console.log(11)
                this.bonFireAttack2(this.bonFireArr2[i])
            }
            if (this.plantArr2.length == 0) return
            for (var i = 0; i < 8; i++) {
                if(this.road2.children[i]==null)continue
                this.checkAttack2(this.road2.children[i])
            }
        }
        if (this.enemyArr3.length != 0) {
            for (var i = 0; i < this.bonFireArr3.length; i++) {
                this.bonFireAttack3(this.bonFireArr3[i])
            }
            if (this.plantArr3.length == 0) return
            for (var i = 0; i < 8; i++) {
                if(this.road3.children[i]==null)continue
                this.checkAttack3(this.road3.children[i])
            }
        }
        if (this.enemyArr4.length != 0) {
            for (var i = 0; i < this.bonFireArr4.length; i++) {
                this.bonFireAttack4(this.bonFireArr4[i])
            }
            if (this.plantArr4.length == 0) return
            for (var i = 0; i < 8; i++) {
                if(this.road4.children[i]==null)continue
                this.checkAttack4(this.road4.children[i])
            }
        }
        if (this.enemyArr5.length != 0) {
            for (var i = 0; i < this.bonFireArr5.length; i++) {
                this.bonFireAttack5(this.bonFireArr5[i])
            }
            if (this.plantArr5.length == 0) return
            for (var i = 0; i < 8; i++) {
                if(this.road5.children[i]==null)continue
                this.checkAttack5(this.road5.children[i])
            }
        }
    }

    // 创建攻击手
    createPlant() {
        // 当已种植攻击手数量等于可种植上限时，不可以继续种植
        if (this.isPlantNums == this.plantNums) return
        console.log("创建攻击手")
        if (this.plantsNode.children.length == 0) {
            // 创建攻击手预制节点
            let plantNode = instantiate(this.prePlantNode);
            // 攻击手是否种下 0为未种下，1为种下
            plantNode['isdown'] = 0;
            // 攻击手是否处于射击状态 0为不在射击，1为正在射击
            plantNode['isFire'] = 0;
            // 攻击手是否在规定格子内
            plantNode['isgrid'] = 0;
            // 将新建攻击手节点添加至攻击手组
            this.plantsNode.addChild(plantNode)
            // 播放种植音效
            this.audioManager.playSound()
        } else if (this.plantsNode.children[this.plantsNode.children.length - 1]['isdown'] == 1) {
            // 创建攻击手预制节点
            let plantNode = instantiate(this.prePlantNode);
            // 攻击手是否种下
            plantNode['isdown'] = 0;
            // 攻击手是否处于射击状态 0为不在射击，1为正在射击
            plantNode['isFire'] = 0;
            // 攻击手是否在规定格子内
            plantNode['isgrid'] = 0;
            // 将新建攻击手节点添加至攻击手组
            this.plantsNode.addChild(plantNode)
            // 播放种植音效
            this.audioManager.playSound()
        }
    }
    // 创建火堆
    createBonfire(){
        // 当已放置火堆数量等于可种植上限时，不可以继续放置
        if (this.isbonfireNums == this.bonfireNums) return
        console.log("创建火堆")
        // 创建攻击手预制节点
        let bonfireNode = instantiate(this.bonFirePrefab);
        // 火堆是否放置 0为未放置，1为已放置
        bonfireNode['isdown'] = 0;
        // 火堆是否在规定格子内
        bonfireNode['isgrid'] = 0;
        this.bonFireArr.addChild(bonfireNode)
    }
    // 敌人经过火堆，火堆对敌人造成伤害
    bonFireAttack1(bonfire){
        if (this.enemyArr1.length == 0) { return }
        // 使用for循环来进行火堆一次对多个敌人造成伤害
        for (var i = 0;i< this.enemyArr1.length;i++){
            let dis = 0;
            dis = Vec3.distance(bonfire.worldPosition, this.enemyArr1[i].worldPosition);
            if(dis<=50){
                this.enemyArr1[i]['Hp'] -= this.bonFireATk
                // 播放敌人受击动画
                let ani = this.enemyArr1[i].getComponent(Animation);
                ani.play('曼波')
            }
            if (this.enemyArr1[i]['Hp'] <= 0) {
                // 每击杀一个敌人分数加5
                this.score += this.enemyHp;
                this.getScore.string = String("当前得分:"+this.score)
                // 播放敌人死亡动画
                let ani2 = this.enemyArr1[i].getComponent(Animation);
                ani2.play('曼波Died')
                // 敌人死亡音效
                this.audioManager_manbo.playSound()
                // 停止敌人缓动
                this.enemyArr1[i]['tween'].stop()
                this.enemyArr1.splice(i, 1)
                let buffNum = Math.random();
                if (buffNum < this.getBuffChance) {
                    this.showBuff()
                }
            }
        }
    }
    bonFireAttack2(bonfire){
        if (this.enemyArr2.length == 0) { return }
        // 使用for循环来进行火堆一次对多个敌人造成伤害
        for (var i = 0;i< this.enemyArr2.length;i++){
            let dis = 0;
            dis = Vec3.distance(bonfire.worldPosition, this.enemyArr2[i].worldPosition);
            console.log(dis)
            if(dis<=50){
                this.enemyArr2[i]['Hp'] -= this.bonFireATk
                // 播放敌人受击动画
                let ani = this.enemyArr2[i].getComponent(Animation);
                ani.play('曼波')
            }
            if (this.enemyArr2[i]['Hp'] <= 0) {
                // 每击杀一个敌人分数加5
                this.score += this.enemyHp;
                this.getScore.string = String("当前得分:"+this.score)
                // 播放敌人死亡动画
                let ani2 = this.enemyArr2[i].getComponent(Animation);
                ani2.play('曼波Died')
                // 敌人死亡音效
                this.audioManager_manbo.playSound()
                // 停止敌人缓动
                this.enemyArr2[i]['tween'].stop()
                this.enemyArr2.splice(i, 1)
                let buffNum = Math.random();
                if (buffNum < this.getBuffChance) {
                    this.showBuff()
                }
            }
        }
    }
    bonFireAttack3(bonfire){
        if (this.enemyArr3.length == 0) { return }
        // 使用for循环来进行火堆一次对多个敌人造成伤害
        for (var i = 0;i< this.enemyArr3.length;i++){
            let dis = 0;
            dis = Vec3.distance(bonfire.worldPosition, this.enemyArr3[i].worldPosition);
            if(dis<=50){
                this.enemyArr3[i]['Hp'] -= this.bonFireATk
                // 播放敌人受击动画
                let ani = this.enemyArr3[i].getComponent(Animation);
                ani.play('曼波')
            }
            if (this.enemyArr3[i]['Hp'] <= 0) {
                // 每击杀一个敌人分数加5
                this.score += this.enemyHp;
                this.getScore.string = String("当前得分:"+this.score)
                // 播放敌人死亡动画
                let ani2 = this.enemyArr3[i].getComponent(Animation);
                ani2.play('曼波Died')
                // 敌人死亡音效
                this.audioManager_manbo.playSound()
                // 停止敌人缓动
                this.enemyArr3[i]['tween'].stop()
                this.enemyArr3.splice(i, 1)
                let buffNum = Math.random();
                if (buffNum < this.getBuffChance) {
                    this.showBuff()
                }
            }
        }
    }
    bonFireAttack4(bonfire){
        if (this.enemyArr4.length == 0) { return }
        // 使用for循环来进行火堆一次对多个敌人造成伤害
        for (var i = 0;i< this.enemyArr4.length;i++){
            let dis = 0;
            dis = Vec3.distance(bonfire.worldPosition, this.enemyArr4[i].worldPosition);
            if(dis<=50){
                this.enemyArr4[i]['Hp'] -= this.bonFireATk
                // 播放敌人受击动画
                let ani = this.enemyArr4[i].getComponent(Animation);
                ani.play('曼波')
            }
            if (this.enemyArr4[i]['Hp'] <= 0) {
                // 每击杀一个敌人分数加5
                this.score += this.enemyHp;
                this.getScore.string = String("当前得分:"+this.score)
                // 播放敌人死亡动画
                let ani2 = this.enemyArr4[i].getComponent(Animation);
                ani2.play('曼波Died')
                // 敌人死亡音效
                this.audioManager_manbo.playSound()
                // 停止敌人缓动
                this.enemyArr4[i]['tween'].stop()
                this.enemyArr4.splice(i, 1)
                let buffNum = Math.random();
                if (buffNum < this.getBuffChance) {
                    this.showBuff()
                }
            }
        }
    }
    bonFireAttack5(bonfire){
        if (this.enemyArr5.length == 0) { return }
        // 使用for循环来进行火堆一次对多个敌人造成伤害
        for (var i = 0;i< this.enemyArr5.length;i++){
            let dis = 0;
            dis = Vec3.distance(bonfire.worldPosition, this.enemyArr5[i].worldPosition);
            if(dis<=50){
                this.enemyArr5[i]['Hp'] -= this.bonFireATk
                // 播放敌人受击动画
                let ani = this.enemyArr5[i].getComponent(Animation);
                ani.play('曼波')
            }
            if (this.enemyArr5[i]['Hp'] <= 0) {
                // 每击杀一个敌人分数加5
                this.score += this.enemyHp;
                this.getScore.string = String("当前得分:"+this.score)
                // 播放敌人死亡动画
                let ani2 = this.enemyArr5[i].getComponent(Animation);
                ani2.play('曼波Died')
                // 敌人死亡音效
                this.audioManager_manbo.playSound()
                // 停止敌人缓动
                this.enemyArr5[i]['tween'].stop()
                this.enemyArr5.splice(i, 1)
                let buffNum = Math.random();
                if (buffNum < this.getBuffChance) {
                    this.showBuff()
                }
            }
        }
    }
    // 创建敌人
    createEnemy() {
        let enemyTween2 = null
        // 创建预制节点
        let enemyNode = instantiate(this.preEnemyNode)
        enemyNode['Hp'] = this.enemyHp;
        // 设置缓动属性
        enemyNode['tween']
        // 设置敌人初始位置
        let roadNum = Math.floor(Math.random() * 5) - 2
        enemyNode.position = new Vec3(450, 10 + roadNum * 120, 0)
        this.enemysNode.addChild(enemyNode)
        this.enemyMove(enemyNode)
        if (enemyNode.position.y == 250) {
            this.enemyArr1.push(enemyNode);
        } else if (enemyNode.position.y == 130) {
            this.enemyArr2.push(enemyNode);
        } else if (enemyNode.position.y == 10) {
            this.enemyArr3.push(enemyNode);
        } else if (enemyNode.position.y == -110) {
            this.enemyArr4.push(enemyNode);
        } else {
            this.enemyArr5.push(enemyNode);
        }
    }
    // 敌人缓动
    enemyMove(enemyNode) {
        // enemyNode.setPosition(new Vec3(450,260,0))
        enemyNode['tween'] = tween(enemyNode)
            // 通过关卡越多，敌人行走速度越快
            .to(this.enemySpeed, { position: new Vec3(-500, enemyNode.position.y, 0) })
            .call(() => {
                Director.instance.end()
                this.endScore.string = String("最终得分:"+this.score)
                this.gameOver()
            })
            .start();
    }
    // 敌人生成的定时器
    createEnemyTimer() {
        let timer1 = null;
        // 设置一个定时器，每隔十秒敌人血量与生成速度增加
        let timer2 = null;
        let count = 0;
        timer2 = setInterval(() => {
            count += 1
            if (count == 20) {
                count = 0
                this.enemyHp += 1
                console.log(this.enemyHp, "HP")
            }
            this.createEnemy()
        }, this.createSpeed)
        timer1 = setInterval(() => {
            clearInterval(timer2)
            timer2 = setInterval(() => {
                count += 1
                if (count == 10) {
                    count = 0
                    this.enemyHp += this.addHp
                    if (this.enemyHp % 50 == 0) {
                        this.addHp += 10
                    }
                    console.log(this.enemyHp, "HP")
                }
                this.createEnemy()
            }, this.createSpeed)
            this.createSpeed -= 100
            if (this.createSpeed < 1000) {
                this.createSpeed = 1000
            }

        }, 10000)
    }
    // 敌人吃掉攻击手
    eatPlant(plantNode) {
        if (plantNode.position == null) return
        let dis = 0;
        if (plantNode.position.y == 250) {
            if (this.plantArr1.length == 0) return
            dis = Vec3.distance(plantNode.position, this.enemyArr1[0].position);
        } else if (plantNode.position.y == 130) {
            if (this.plantArr2.length == 0) return
            dis = Vec3.distance(plantNode.position, this.enemyArr2[0].position);
        } else if (plantNode.position.y == 10) {
            if (this.plantArr3.length == 0) return
            dis = Vec3.distance(plantNode.position, this.enemyArr3[0].position);
        } else if (plantNode.position.y == -110) {
            if (this.plantArr4.length == 0) return
            dis = Vec3.distance(plantNode.position, this.enemyArr4[0].position);
        } else {
            if (this.plantArr5.length == 0) return
            dis = Vec3.distance(plantNode.position, this.enemyArr5[0].position);
        }
        if (dis <= 50) {
            console.log("攻击手被吃掉啦");
            if (plantNode.position.y == 250) {
                this.plantArr1[plantNode['num']]==null
                plantNode['isFire'] = 0;
                plantNode.active = false
                this.plantList[0][plantNode['num']] -= 1
            } else if (plantNode.position.y == 130) {
                this.plantArr2[plantNode['num']]==null
                plantNode['isFire'] = 0;
                plantNode.active = false
                this.plantList[1][plantNode['num']] -= 1
            } else if (plantNode.position.y == 10) {
                this.plantArr3[plantNode['num']]==null
                plantNode['isFire'] = 0;
                plantNode.active = false
                this.plantList[2][plantNode['num']] -= 1
            } else if (plantNode.position.y == -110) {
                this.plantArr4[plantNode['num']]==null
                plantNode['isFire'] = 0;
                plantNode.active = false
                this.plantList[3][plantNode['num']] -= 1
            } else {
                this.plantArr5[plantNode['num']]==null
                plantNode['isFire'] = 0;
                plantNode.active = false
                this.plantList[4][plantNode['num']] -= 1
            }
            plantNode.destroy();
            return
        }
    }
    // 判断1路敌人是否能吃掉攻击手
    checkeat1() {
        if (this.enemyArr1.length != 0) {
            if (this.plantArr1.length == 0) return
            for (var i = 0; i < this.plantArr1.length; i++) {
                if(this.plantArr1[i]!=null){
                    this.eatPlant(this.plantArr1[i])
                }
            }
        }
    }
    // 判断2路敌人是否能吃掉攻击手
    checkeat2() {
        if (this.enemyArr2.length != 0) {
            if (this.plantArr2.length == 0) return
            for (var i = 0; i < this.plantArr2.length; i++) {
                if(this.plantArr2[i]!=null){
                    this.eatPlant(this.plantArr2[i])
                }            }
        }
    }
    // 判断3路敌人是否能吃掉攻击手
    checkeat3() {
        if (this.enemyArr3.length != 0) {
            if (this.plantArr3.length == 0) return
            for (var i = 0; i < this.plantArr3.length; i++) {
                if(this.plantArr3[i]!=null){
                    this.eatPlant(this.plantArr3[i])
                }            }
        }
    }
    // 判断4路敌人是否能吃掉攻击手
    checkeat4() {
        if (this.enemyArr4.length != 0) {
            if (this.plantArr4.length == 0) return
            for (var i = 0; i < this.plantArr4.length; i++) {
                if(this.plantArr4[i]!=null){
                    this.eatPlant(this.plantArr4[i])
                }            }
        }
    }
    // 判断5路敌人是否能吃掉攻击手
    checkeat5() {
        if (this.enemyArr5.length != 0) {
            if (this.plantArr5.length == 0) return
            for (var i = 0; i < this.plantArr5.length; i++) {
                if(this.plantArr5[i]!=null){
                    this.eatPlant(this.plantArr5[i])
                }            }
        }
    }
    // 监测道路1是否有敌人
    checkenemy1() {
        if (this.enemyArr1.length == 0) return
        if (this.plantArr1.length == 0) return
        let road1 = 1;
        for (var i = 0; i < this.plantArr1.length; i++) {
            if(this.plantArr1[i]==null)continue
            if (this.plantArr1[i]['isFire'] == 0) {
                this.plantArr1[i]['isFire'] = 1;
                this.attack(this.plantArr1[i], road1)
            } else {
                continue
            }
        }
    }
    // 监测道路2是否有敌人
    checkenemy2() {
        if (this.enemyArr2.length == 0) return
        if (this.plantArr2.length == 0) return
        let road2 = 2;
        for (var i = 0; i < this.plantArr2.length; i++) {
            if(this.plantArr2[i]==null)continue
            if (this.plantArr2[i]['isFire'] == 0) {
                this.plantArr2[i]['isFire'] = 1;
                
                this.attack(this.plantArr2[i], road2)
            } else {
                continue
            }
        }
    }
    // 监测道路3是否有敌人
    checkenemy3() {
        if (this.enemyArr3.length == 0) return
        if (this.plantArr3.length == 0) return
        let road3 = 3;
        for (var i = 0; i < this.plantArr3.length; i++) {
            if(this.plantArr3[i]==null)continue
            if (this.plantArr3[i]['isFire'] == 0) {
                this.plantArr3[i]['isFire'] = 1;
                this.attack(this.plantArr3[i], road3)
            } else {
                continue
            }
        }
    }
    // 监测道路4是否有敌人
    checkenemy4() {
        if (this.enemyArr4.length == 0) return
        if (this.plantArr4.length == 0) return
        let road4 = 4;
        for (var i = 0; i < this.plantArr4.length; i++) {
            if(this.plantArr4[i]==null)continue
            if (this.plantArr4[i]['isFire'] == 0) {
                this.plantArr4[i]['isFire'] = 1;
                this.attack(this.plantArr4[i], road4)
            } else {
                continue
            }
        }
    }
    // 监测道路5是否有敌人
    checkenemy5() {
        if (this.enemyArr5.length == 0) return
        if (this.plantArr5.length == 0) return
        let road5 = 5;
        for (var i = 0; i < this.plantArr5.length; i++) {
            if(this.plantArr5[i]==null)continue
            if (this.plantArr5[i]['isFire'] == 0) {
                this.plantArr5[i]['isFire'] = 1;
                this.attack(this.plantArr5[i], road5)
            } else {
                continue
            }
        }
    }
    // 攻击
    attack(plantNode, road) {
        // 定时器
        let timer = null;
        timer = setInterval(() => {
            // 当敌人死亡停止攻击
            if (road = 1 && this.enemyArr1.length == 0) {
                clearInterval(timer)
                plantNode['isFire'] = 0;
            }
            if (road == 1 && plantNode.position == null) {
                clearInterval(timer)
                plantNode['isFire'] = 0;
                return
            }
            if (road == 2 && this.enemyArr2.length == 0) {
                clearInterval(timer)
                plantNode['isFire'] = 0;
            }
            if (road == 2 && plantNode.position == null) {
                clearInterval(timer)
                plantNode['isFire'] = 0;
                return
            }
            if (road == 3 && this.enemyArr3.length == 0) {
                clearInterval(timer)
                plantNode['isFire'] = 0;
            }
            if (road == 3 && plantNode.position == null) {
                clearInterval(timer)
                plantNode['isFire'] = 0;
                return
            }
            if (road == 4 && this.enemyArr4.length == 0) {
                clearInterval(timer)
                plantNode['isFire'] = 0;
            }
            if (road == 4 && plantNode.position == null) {
                clearInterval(timer)
                plantNode['isFire'] = 0;
                return
            }
            if (road == 5 && this.enemyArr5.length == 0) {
                clearInterval(timer)
                plantNode['isFire'] = 0;
            }
            if (road == 5 && plantNode.position == null) {
                clearInterval(timer)
                plantNode['isFire'] = 0;
                return
            }

            // 当攻击手被消灭也停止攻击
            if(plantNode.active == false){
                clearInterval(timer)
                plantNode['isFire'] = 0;
                return
            }

            // 子弹预制体
            let bulletNode = instantiate(this.preBulletNode)
            // 设置子弹缓动
            let bulletTween = null;
            bulletNode.active = false;
            // 设置子弹是否发射 0为未发射，1为发射
            bulletNode['isGo'] = 0;
            // 设置子弹初始位置
            bulletNode.worldPosition = new Vec3(plantNode.position.x, 0, 0);
            // 将子弹挂载在攻击手节点
            if (plantNode.position.y == 250) {
                this.road1.addChild(bulletNode)
            } else if (plantNode.position.y == 130) {
                this.road2.addChild(bulletNode)
            } else if (plantNode.position.y == 10) {
                this.road3.addChild(bulletNode)
            } else if (plantNode.position.y == -110) {
                this.road4.addChild(bulletNode)
            } else {
                this.road5.addChild(bulletNode)
            }
            // 根据攻击手所处格子位置分配不同的缓动时间来控制子弹速度
            let bulletSpeed = 0
            if (plantNode.position.x == -420) {
                bulletSpeed = this.Column1
            } else if (plantNode.position.x == -300) {
                bulletSpeed = this.Column2
            } else if (plantNode.position.x == -180) {
                bulletSpeed = this.Column3
            } else if (plantNode.position.x == -60) {
                bulletSpeed = this.Column4
            } else if (plantNode.position.x == 60) {
                bulletSpeed = this.Column5
            } else if (plantNode.position.x == 180) {
                bulletSpeed = this.Column6
            } else if (plantNode.position.x == 300) {
                bulletSpeed = this.Column7
            } else {
                bulletSpeed = this.Column8
            }
            // 子弹缓动
            bulletNode.active = true;
            bulletTween = tween(bulletNode)
                .to(bulletSpeed, { position: new Vec3(1000, 0, 0) })
                .call(() => {
                    bulletNode.destroy()
                })
                .start();
        }, this.plantSpeed)

    }
    
    // 当子弹穿过火堆时，子弹被“附魔”，伤害提升20%(穿过多个伤害增幅可叠加)
    buffPlant(){

    }
    // 监测子弹是否攻击到敌人
    checkAttack1(bulletNode) {
        if (this.enemyArr1.length == 0) { return }
        let dis = 0;
        dis = Vec3.distance(bulletNode.worldPosition, this.enemyArr1[0].worldPosition);
        if (dis <= 50) {
            if (bulletNode['isGo'] == 1) return
            bulletNode['isGo'] = 1;
            // 子弹击中敌人，子弹消失
            bulletNode.destroy();
            // 隐藏子弹
            // 子弹命中敌人，敌人扣血，利用循环可便于挂贯穿伤buff
            // 使用for循环来进行贯穿伤实现，当该路段敌人数大于等于贯穿数时，可以造成贯穿伤
            for (var i = 0; i <= this.crossNums; i++) {
                if (i >= this.enemyArr1.length) return
                this.enemyArr1[i]['Hp'] -= this.plantATK;
                // 播放敌人受击动画
                let ani = this.enemyArr1[i].getComponent(Animation);
                ani.play('曼波')
                if (this.enemyArr1[i]['Hp'] <= 0) {
                    // 每击杀一个敌人分数加5
                    this.score += this.enemyHp;
                    this.getScore.string = String("当前得分:"+this.score)
                    // 播放敌人死亡动画
                    let ani2 = this.enemyArr1[i].getComponent(Animation);
                    ani2.play('曼波Died')
                    // this.enemyArr1[i].active = false;
                    // 敌人死亡音效
                this.audioManager_manbo.playSound()
                // 停止敌人缓动
                    // 停止缓动
                    this.enemyArr1[i]['tween'].stop()
                    // 1秒后将敌人节点删除（播放完动画后）
                    // let died = null
                    // died = setInterval(()=>{
                        // this.enemyArr1[i].destroy()
                        // clearInterval(died)
                    // },1000)
                    this.enemyArr1.splice(i, 1)
                    let buffNum = Math.random();
                    if (buffNum < this.getBuffChance) {
                        this.showBuff()
                    }
                }
            }
        }
    }
    checkAttack2(bulletNode) {
        if (this.enemyArr2.length == 0) { return }
        let dis = 0;
        dis = Vec3.distance(bulletNode.worldPosition, this.enemyArr2[0].worldPosition);
        if (dis <= 50) {
            if (bulletNode['isGo'] == 1) return
            bulletNode['isGo'] = 1;
            // 子弹击中敌人，子弹消失
            bulletNode.destroy();
            // 隐藏子弹
            // 子弹命中敌人，敌人扣血，利用循环可便于挂贯穿伤buff
            // 使用for循环来进行贯穿伤实现，当该路段敌人数大于等于贯穿数时，可以造成贯穿伤
            for (var i = 0; i <= this.crossNums; i++) {
                if (i >= this.enemyArr2.length) return
                this.enemyArr2[i]['Hp'] -= this.plantATK;
                console.log(this.enemyArr2[i]['Hp'], 2)
                // 播放敌人受击动画
                let ani = this.enemyArr2[i].getComponent(Animation);
                ani.play('曼波')
                if (this.enemyArr2[i]['Hp'] <= 0) {
                    // 每击杀一个敌人分数加5
                    this.score += this.enemyHp;
                    this.getScore.string = String("当前得分:"+this.score)
                    // 播放敌人死亡动画
                    let ani2 = this.enemyArr2[i].getComponent(Animation);
                    ani2.play('曼波Died')
                    // this.enemyArr2[i].active = false;
                    // 敌人死亡音效
                this.audioManager_manbo.playSound()
                // 停止敌人缓动
                    // 停止缓动
                    this.enemyArr2[i]['tween'].stop()
                    // 1秒后将敌人节点删除（播放完动画后）
                    // let died = null
                    // died = setInterval(()=>{
                        // this.enemyArr2[i].destroy()
                        // clearInterval(died)
                    // },1000)
                    this.enemyArr2.splice(i, 1)
                    let buffNum = Math.random();
                    if (buffNum < this.getBuffChance) {
                        this.showBuff()
                    }
                }
            }


        }
    }
    checkAttack3(bulletNode) {
        if (this.enemyArr3.length == 0) return
        let dis = 0;
        dis = Vec3.distance(bulletNode.worldPosition, this.enemyArr3[0].worldPosition);
        if (dis <= 50) {
            if (bulletNode['isGo'] == 1) return
            bulletNode['isGo'] = 1;
            // 子弹击中敌人，子弹消失
            bulletNode.destroy();
            // 隐藏子弹
            // 子弹命中敌人，敌人扣血，利用循环可便于挂贯穿伤buff
            // 使用for循环来进行贯穿伤实现，当该路段敌人数大于等于贯穿数时，可以造成贯穿伤
            for (var i = 0; i <= this.crossNums; i++) {
                if (i >= this.enemyArr3.length) return
                this.enemyArr3[i]['Hp'] -= this.plantATK;
                // 播放敌人受击动画
                let ani = this.enemyArr3[i].getComponent(Animation);
                ani.play('曼波')
                if (this.enemyArr3[i]['Hp'] <= 0) {
                    // 每击杀一个敌人分数加5
                    this.score += this.enemyHp;
                    this.getScore.string = String("当前得分:"+this.score)
                    // 播放敌人死亡动画
                    let ani2 = this.enemyArr3[i].getComponent(Animation);
                    ani2.play('曼波Died')
                    // this.enemyArr3[i].active = false;
                    // 敌人死亡音效
                this.audioManager_manbo.playSound()
                // 停止敌人缓动
                    // 停止缓动
                    this.enemyArr3[i]['tween'].stop()
                    // 1秒后将敌人节点删除（播放完动画后）
                    // let died = null
                    // died = setInterval(()=>{
                        // this.enemyArr3[i].destroy()
                        // clearInterval(died)
                    // },1000)
                    this.enemyArr3.splice(0, 1)
                    let buffNum = Math.random();
                    if (buffNum < this.getBuffChance) {
                        this.showBuff()
                    }
                }
            }


        }
    }
    checkAttack4(bulletNode) {
        if (this.enemyArr4.length == 0) { return }
        let dis = 0;
        dis = Vec3.distance(bulletNode.worldPosition, this.enemyArr4[0].worldPosition);
        if (dis <= 50) {
            if (bulletNode['isGo'] == 1) return
            bulletNode['isGo'] = 1;
            // 子弹击中敌人，子弹消失
            bulletNode.destroy();
            // 隐藏子弹
            // 子弹命中敌人，敌人扣血，利用循环可便于挂贯穿伤buff
            // 使用for循环来进行贯穿伤实现，当该路段敌人数大于等于贯穿数时，可以造成贯穿伤
            for (var i = 0; i <= this.crossNums; i++) {
                if (i >= this.enemyArr4.length) return
                this.enemyArr4[i]['Hp'] -= this.plantATK;
                // 播放敌人受击动画
                let ani = this.enemyArr4[i].getComponent(Animation);
                ani.play('曼波')
                if (this.enemyArr4[i]['Hp'] <= 0) {
                    // 每击杀一个敌人分数加5
                    this.score += this.enemyHp;
                    this.getScore.string = String("当前得分:"+this.score)
                    // 播放敌人死亡动画
                    let ani2 = this.enemyArr4[i].getComponent(Animation);
                    ani2.play('曼波Died')
                    // this.enemyArr4[i].active = false;
                    // 敌人死亡音效
                this.audioManager_manbo.playSound()
                // 停止敌人缓动
                    // 停止缓动
                    this.enemyArr4[i]['tween'].stop()
                    // 1秒后将敌人节点删除（播放完动画后）
                    // let died = null
                    // died = setInterval(()=>{
                        // this.enemyArr4[i].destroy()
                        // clearInterval(died)
                    // },1000)
                    this.enemyArr4.splice(i, 1)
                    let buffNum = Math.random();
                    if (buffNum < this.getBuffChance) {
                        this.showBuff()
                    }
                }
            }


        }
    }
    checkAttack5(bulletNode) {
        if (this.enemyArr5.length == 0) { return }
        let dis = 0;
        dis = Vec3.distance(bulletNode.worldPosition, this.enemyArr5[0].worldPosition);
        if (dis <= 50) {
            if (bulletNode['isGo'] == 1) return
            bulletNode['isGo'] = 1;
            // 子弹击中敌人，子弹消失
            bulletNode.destroy();
            // 隐藏子弹
            // 子弹命中敌人，敌人扣血，利用循环可便于挂贯穿伤buff
            // 使用for循环来进行贯穿伤实现，当该路段敌人数大于等于贯穿数时，可以造成贯穿伤
            for (var i = 0; i <= this.crossNums; i++) {
                if (i >= this.enemyArr5.length) return
                this.enemyArr5[i]['Hp'] -= this.plantATK;
                // 播放敌人受击动画
                let ani = this.enemyArr5[i].getComponent(Animation);
                ani.play('曼波')
                if (this.enemyArr5[i]['Hp'] <= 0) {
                    // 每击杀一个敌人分数根据敌人血量多少来增加
                    this.score += this.enemyHp;
                    this.getScore.string = String("当前得分:"+this.score)
                    // 播放敌人死亡动画
                    let ani2 = this.enemyArr5[i].getComponent(Animation);
                    ani2.play('曼波Died')
                    // this.enemyArr5[i].active = false;
                    // 敌人死亡音效
                this.audioManager_manbo.playSound()
                // 停止敌人缓动
                    // 停止缓动
                    this.enemyArr5[i]['tween'].stop()
                    // 1秒后将敌人节点删除（播放完动画后）
                    // let died = null
                    // died = setInterval(()=>{
                        // this.enemyArr5[i].destroy()
                        // clearInterval(died)
                    // },1000)
                    this.enemyArr5.splice(i, 1)
                    let buffNum = Math.random();
                    if (buffNum < this.getBuffChance) {
                        this.showBuff()
                    }
                }
            }
        }
    }

    // 为攻击手选择buff
    // 每10秒为玩家提供一次buff,最多十次
    getbuff() {
        let timer = null
        let sums = 0
        timer = setInterval(() => {
            sums += 1
            this.showBuff()
            if (sums == 10) {
                clearInterval(timer)
            }
        }, 10000)
    }
    // 在buff库中随机选择三种Buff展示，供玩家选择
    showBuff() {
        if (this.isBuff == 1) return
        // 放选择buff达到20时，解锁火堆
        if(this.getBuffNums == 3){
            this.Buffs.push(this.buff5)
        }
        // 玩家每选择5次buff减小获得buff概率
        if (this.getBuffNums % 10 == 0) {
            console.log(this.getBuffChance,"chance")
            if (this.getBuffChance <= 0.03) return
            this.getBuffChance -= 0.01
        }
        // 玩家最多选择100次buff
        if(this.getBuffNums>=100){return}
        // Director.instance.pause()
        this.Tip.active = true
        while (true) {
            let index1 = Math.floor(Math.random() * this.Buffs.length)
            let index2 = Math.floor(Math.random() * this.Buffs.length)
            let index3 = Math.floor(Math.random() * this.Buffs.length)
            if (index1 != index2 && index2 != index3 && index1 != index3) {
                this.Buffs[index1].setPosition(new Vec3(-50, 100, 0))
                this.Buffs[index2].setPosition(new Vec3(-50, 0, 0))
                this.Buffs[index3].setPosition(new Vec3(-50, -100, 0))
                break
            } else {
                continue
            }
        }
        // buff产生，在选择前不会继续生成
        this.isBuff = 1
    }
    // 攻速+50 最小值为700
    getBuff1() {
        console.log(this.plantSpeed)
        this.plantSpeed -= 50;
        this.getBuffblack()
        // 当攻击间隔小于等于600时，将该buff从buffo(╥﹏╥)库中删除，即无法进行减小攻击间隔
        if (this.plantSpeed <= 700) {
            this.Buffs.splice(0,1)
            console.log(this.Buffs)
        }
    }
    // 攻击力+2
    getBuff2() {
        this.plantATK += 2;
        this.getBuffblack()
    }
    // 攻击造成贯穿，但伤害-1
    getBuff3() {
        this.plantATK -= 1;
        this.crossNums += 1;
        this.getBuffblack()
    }
    // 可种植攻击手+2
    getBuff4() {
        this.plantNums += 2;
        this.getBuffblack()
    }
    // 可放置火堆数+1，上限5
    getBuff5(){
        this.bonfireNums += 1;
        this.getBuffblack()
        if (this.bonfireNums >= 5) {
            this.Buffs.splice(4,1)
            console.log(this.Buffs)
        }
    }
    // 将选择buff后续操作写成一个方法减少代码重复
    getBuffblack(){
        this.getBuffNums += 1;
        // 修改获得buff数量文本
        this.buffsumsLabel.string = String("当前获得buff数量:"+this.getBuffNums)
        this.Tip.active = false;
        for (var i = 0; i < this.Buffs.length; i++) {
            this.Buffs[i].setPosition(new Vec3(-1000, -1000, 0))
        }
        // 已选择buff，可以继续生成buff
        this.isBuff = 0
    }
}
